package io.ouka.jvm.hotspot.selfread.read;

import io.ouka.jvm.hotspot.selfread.InstanceKlass;
import io.ouka.jvm.hotspot.selfread.constant.FinalConstant;
import io.ouka.jvm.hotspot.selfread.util.DataTranslate;

/**
 * @author Ouka
 */
public class MagicReader extends AbstractReader {

    public MagicReader() {
        this.iReader = new MainVersionReader();
    }

    @Override
    public void preRead(byte[] content) {
        byte[] bytes = new byte[FinalConstant.u4];
        for (int i = 0; i < content.length; i++) {
            bytes[i] = content[i];
            if (i >= FinalConstant.u4 - 1) {
                this.selfContent = bytes;
                index = FinalConstant.u4;
                return;
            }
        }

    }

    @Override
    public void read() {
        instanceKlass.setMagic(DataTranslate.byteArrayToInt(selfContent));
    }


}
